package com.zhaowenhao.bean;

import com.sun.org.apache.regexp.internal.REUtil;

import java.util.HashMap;

/**
 * Description:通用信息返回类 100成功  0失败
 * User: zwh
 * Date: 2019-06-05
 * Time: 20:06
 */
public class Msg {

    //状态码
    private int code;

    //提示信息
    private String msg;

    //要返回给前端浏览器的数据
    private HashMap<String, Object> extend = new HashMap<>();

    /**
     * 通过静态方法直接返回一个成功信息
     *
     * @return
     */
    public static Msg success() {
        Msg msg = new Msg();
        msg.setCode(100);
        msg.setMsg("success");
        return msg;
    }

    /**
     * 通过静态方法直接返回一个失败信息
     *
     * @return
     */
    public static Msg failed() {
        Msg msg = new Msg();
        msg.setCode(0);
        msg.setMsg("failed");
        return msg;
    }

    /**
     * 成功之后可以链式调用添加附加数据的方法
     *
     * @param key
     * @param value
     * @return
     */
    public Msg addExtend(String key, Object value) {
        this.getExtend().put(key, value);
        return this;
    }

    public Msg() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public HashMap<String, Object> getExtend() {
        return extend;
    }

    public void setExtend(HashMap<String, Object> extend) {
        this.extend = extend;
    }
}
